package com.zl.study.mybatis.demo;

import com.zl.study.mybatis.demo.entity.Blog;
import com.zl.study.mybatis.demo.mapper.BlogMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class InsertTestMain {

  public static void main(String[] args) throws IOException {

    SqlSessionFactory ssf = MyBatisUtils.getSqlSessionFactory();

    try(SqlSession session = ssf.openSession()) {
      BlogMapper blogMapper = session.getMapper(BlogMapper.class);
      Blog blog = new Blog();
      blog.setTitle("很好啊~~~");
      blog.setAuthorId(10);
      blogMapper.insert(blog);
      System.out.println("blog's id is " + blog.getId());
      session.commit();
    }
  }
}
